package top.tenebrous.yzl.handler.sechub;

import org.springframework.beans.factory.InitializingBean;
import top.tenebrous.yzl.chain.AbstractJesticChainHandler;
import top.tenebrous.yzl.context.JesticTask;
import top.tenebrous.yzl.context.Response;
import top.tenebrous.yzl.enums.TaskEnum;
import top.tenebrous.yzl.factorys.JesticPropertyChainFactory;
import top.tenebrous.yzl.handler.AbstractJesticInitInterface;
//import top.tenebrous.yzl.handler.authority.AuthorityHandler;
import top.tenebrous.yzl.instance.AbstractInstanceContext;
import top.tenebrous.yzl.mapper.JesticServerMapper;
import top.tenebrous.yzl.service.IAuthorityService;

import javax.annotation.Resource;

/**
 * @author yazhang6
 */
public class JesticSechubInitHandler <T extends JesticTask, C extends Response> implements AbstractJesticInitInterface<T, C>, InitializingBean {

    @Resource
    private JesticPropertyChainFactory<T, C> jesticPropertyChainFactory;

    @Resource
    private AbstractInstanceContext abstractInstanceContext;

    @Resource
    private IAuthorityService authorityService;

    @Override
    public void afterPropertiesSet() throws Exception {
        AbstractJesticChainHandler<T, C> handler = buildBuilder();
        jesticPropertyChainFactory.register(getTaskType().getCode(), handler);
    }

    @Override
    public AbstractJesticChainHandler<T, C> buildBuilder() {
        AbstractJesticChainHandler.Builder<T, C> builder = new AbstractJesticChainHandler.Builder<>();
        return builder
                .addHandler((AbstractJesticChainHandler<T, C>) new JesticSechubCheckHandler(abstractInstanceContext, authorityService))
                .addHandler((AbstractJesticChainHandler<T, C>) new JesticSechubHandler())
                .build();
    }

    @Override
    public TaskEnum getTaskType() {
        return TaskEnum.SECHUB;
    }

}
